package com.mirai.mirai_boot.utils;

import org.jsoup.Jsoup;
import org.springframework.stereotype.Component;

import java.io.IOException;

import static org.apache.http.HttpHeaders.USER_AGENT;

/**
 * @author : CP
 * @version: 1.0
 * @program : mirai_boot
 * @description :
 * @date : 2021-07-02 07:41
 **/
@Component
public class JsoupUtils {

    /**
     * 爬取网页 json 数据
     * @param url
     * @return
     * @throws IOException
     */
    public static String connect(String url) throws IOException {
        String body = Jsoup.connect(url)
                .header("User-Agent", USER_AGENT)
                .timeout(3000)
                .ignoreContentType(true)
                .get().select("body")
                .text();
        return body;
    }
}
